<?php
declare (strict_types=1);

namespace app\mall\logic\product;

use app\common\exception\LogicException;
use app\mall\event\subscribes\Sale;
use app\mall\model\product\ProductSale as ProductSaleMod;
use think\facade\Event;

class ProductSale extends ProductSaleMod
{

    public function addProductSale($prodId, $mid, $orderSubNo)
    {
        $res = $this::create([
            'product_id'   => $prodId,
            'user_id'      => $mid,
            'order_sub_no' => $orderSubNo,
        ]);
        if ($res->isEmpty()) throw new LogicException('处理商品销量');
        Event::subscribe(Sale::class);
        Event::trigger('AfterSale', $res);
    }
}
